package com.zhuss.meeting.processor;

import com.zhuss.bean.bo.meeting.room.DeleteRoomBo;
import com.zhuss.bean.vo.meeting.room.DetailRoomVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.meeting.db.dao.ext.MeetingRoomDao;
import com.zhuss.meeting.db.entity.MeetingRoom;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 删除用户 processor
 * @Author: zhushanshuo
 * @Date: 2019/9/24 19:54
 */
@Component("roomDelete")
public class RoomDelete extends AbstractProcessor<Object, DeleteRoomBo> implements Processor<Object, DeleteRoomBo> {

	@Autowired
	private MeetingRoomDao roomDao;

	@Autowired
	@Qualifier("roomRead")
	private RoomRead roomRead;


	@Override
	public Object process(DeleteRoomBo deleteRoomBo) throws WpsException {
		Long roomId = deleteRoomBo.getRoomId();
		String name = ((DetailRoomVo) roomRead.detail(roomId)).getName();

		MeetingRoom meetingRoom =new MeetingRoom();
		meetingRoom.setRoomId(deleteRoomBo.getRoomId());
		meetingRoom.setDeleted(deleteRoomBo.getDeleted());

		meetingRoom.setModifierId(deleteRoomBo.getConcurrentUserId());
		meetingRoom.setModifier(deleteRoomBo.getConcurrentUserName());
		meetingRoom.setModifyTime(new Date());
		roomDao.delete(meetingRoom);
		deleteRoomBo.setName(name);
		return null;
	}

	@Override
	public Object log(DeleteRoomBo param) throws WpsException {
		OpLog record = new OpLog();
		record.setMoudle(MoudleEnum.会务.key());
		record.setAction(LogActionEnum.会议室删除.key());
		record.setTargetId(param.getRoomId());
		record.setTargetName(param.getName());
		record.setContent("参数: " + JsonUtil.toJson(param));
		record.setReason(param.getExceptionReason());

		record.setCreatorId(param.getConcurrentUserId());
		record.setCreator(param.getConcurrentUserName());
		record.setCreateTime(new Date());
		log(record);
		return null;
	}

	@Override
	public void check(DeleteRoomBo deleteRoomBo) throws WpsException {

	}
}
